package com.yz.study.test;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

public class T2
{
    public int add(int x ,int y)
    {
        return x + y;
    }

    public int getUserById(Integer id)
    {
        return 666;
    }

    public static void main(String[] args)
    {
        Method[] methods = T2.class.getDeclaredMethods();
        for (Method method : methods) {
            System.out.println(method.getName());
            if("getUserById".equalsIgnoreCase(method.getName()))
            {
                /*System.out.println("--11111");
                DefaultParameterNameDiscoverer discover = new DefaultParameterNameDiscoverer();
                String[] parameterNames = discover.getParameterNames(method);
                System.out.println(parameterNames.length);*/

                System.out.println("--2222");
                // 获取方法的参数
                Parameter[] parameters = method.getParameters();
                for (Parameter parameter : parameters) {
                    // 输出参数名和类型
                    System.out.println("Parameter Type: " + parameter.getType().getName());
                    System.out.println("Parameter Name: " + parameter.getName());
                }

            }
        }
    }

}
